component extends="Controller" output="false" {
  
  public void function init(){
  }
  
  // teams/index
  public void function index(){
    teams = model("Team").findAll();
  }
  
  // teams/show/key
  public void function show(){
    team = model("Team").findByKey(params.key);
    	
    if (!IsObject(team)){
      flashInsert(error="Team #params.key# was not found");
      redirectTo(action="index");
    }
  }
  
  // teams/new
  public void function new(){
    team = model("Team").new();
  }
  
  //teams/edit/key
  public void function edit(){
    team = model("Team").findByKey(params.key);
    	
    if (!IsObject(team)){
	    flashInsert(error="Team #params.key# was not found");
			redirectTo(action="index");
	  }
  }
  
  // teams/create
  public void function create(){
    team = model("Team").new(params.team);
		
		if (team.save()){
			flashInsert(success="The team was created successfully.");
      redirectTo(action="index");
		} else {
		  flashInsert(error="There was an error creating the team.");
		  renderPage(action="new");
		}
  }
  
  // teams/update
  public void function update(){
    team = model("Team").findByKey(params.key);
		
		if (team.update(params.team)){
		  flashInsert(success="The team was updated successfully.");
      redirectTo(action="index");
		} else {
		  flashInsert(error="There was an error updating the team.");
			renderPage(action="edit");
		}
  }
  
  // teams/delete/key
  public void function delete(){
    team = model("Team").findByKey(params.key);

		if (team.delete()){
			flashInsert(success="The team was deleted successfully.");
      redirectTo(action="index");
    } else {
      flashInsert(error="There was an error deleting the team.");
			redirectTo(action="index");
    }
  }
  
}
